﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Threading;
using System.Threading;
using System.Diagnostics;
using Moop.UI.Common;

namespace Moop.UI
{
    public sealed class AppContext : IAppContext
    {
        private readonly Dispatcher _dispatcher;
        public bool IsSynchronized { get { return this._dispatcher.Thread == Thread.CurrentThread; } }

        public AppContext() : this(Dispatcher.CurrentDispatcher)
        {
        }

        public AppContext(Dispatcher dispatcher)
        {
            Debug.Assert(dispatcher != null);
            this._dispatcher = dispatcher;
        }

        public void Invoke(Action action)
        {
            Debug.Assert(action != null);
            this._dispatcher.Invoke(action);
        }

        public void BeginInvoke(Action action)
        {
            Debug.Assert(action != null);
            this._dispatcher.BeginInvoke(action);
        }
    }
}
